﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Microsoft.Kinect;
using System.Windows;

namespace VideoMagic
{
    public struct VideoMagicImage
    {
        const int bytesPerDepthPixel = 2;
        const int bytesPerColorPixel = 4;
        static Int32Rect _ViewPort;

        public VideoMagicImage(int width, int height)
        {
            this.Width = width;
            this.Height = height;
            this.ColorStride = width * bytesPerColorPixel;
            this.DepthStride = width * bytesPerDepthPixel;
            this.PixelCount = width * height;

            _ViewPort = new Int32Rect(0, 0, Width, Height);

            ColorData = new byte[PixelCount * bytesPerColorPixel];
            DepthData = new short[PixelCount];
            //DepthData = new DepthImagePixel[PixelCount];
            DepthDataMapped = new ColorImagePoint[PixelCount];

            ColorBitmap = new WriteableBitmap(width, height, 96, 96, PixelFormats.Bgr32, null);
            DepthBitmap = new WriteableBitmap(width, height, 96, 96, PixelFormats.Gray16, null);

            ColorBrush = new ImageBrush(ColorBitmap);
            DepthBrush = new ImageBrush(DepthBitmap);
        } 

        public int Width;
        public int Height;
        public int ColorStride;
        public int DepthStride;
        public int PixelCount;
        public byte[] ColorData;
        public short[] DepthData;

        //public DepthImagePixel[] DepthData;
        public ColorImagePoint[] DepthDataMapped;

        public Brush ColorBrush;
        public Brush DepthBrush;

        public WriteableBitmap ColorBitmap;
        public WriteableBitmap DepthBitmap;

        public void UpdateBitmaps()
        {
            ColorBitmap.WritePixels(_ViewPort, ColorData, ColorStride, 0);
            DepthBitmap.WritePixels(_ViewPort, DepthDataMapped, DepthStride, 0);
        }
    }
}
